
$("#addProblem").click(
    function () {
        addProblem();
    }
);
$("#saveBtn").click(function () {
    var aa = "nosave";
    savepaper();
});

var savepaper = function (aa) {
    layer.confirm('是否保留试卷内容？', {
            btn: ['是', '否']
        }, function () {
            save();

        }, function () {
            if (aa == "returnlistpaper") {
                returnListPaper();
            }
        }
    )
};
var save = function () {
    var a = aop.onlyList.concat(aop.manyList);
    var cont = aop.judgeList.concat(a);
    var cc = {
        con:{
            cont:cont
        },
        type:{
            only:parseInt(aop.types.only),
            many:parseInt(aop.types.many.a),
            judge:parseInt(aop.types.judge)
        },
        paper: aop.paper
    };
    $.ajax({
        type: "post",
        url: "/paper/sAddPaPer.do",
        data:JSON.stringify(cc),
        contentType: "application/json",
        success: function (data) {
            returnListPaper()
        }
    })

}

$("#returnListPaper").click(
    function () {
        var aa = "returnlistpaper";
        savepaper(aa);
    });
var returnListPaper = function () {
    location.href = "/paper/listPaper.do";

};
var addProblem = function () {
    layer.open({
        type: 2,
        title: "添加试题",
        fix: false,
        maxmin: true,
        shadeClose: false,
        area: ['900px', '600px'],
        content: '/paper/toAddproblem.do',
    });
}
function loadPaper() {
    $.ajax({
        type: "post",
        url: "/paper/loadPaper.do",
        data: {
            paper_id: $("#paperid").val()
        },
        dataType: "json",
        success: function (data) {
            //试卷所有属性
            aop.paper = data.paper;
            //考试时间存放在cookie中
            //单选题库
            aop.onlyList = data.onlyList;
            //多选题库
            aop.manyList = data.manyList;
            //判断题库
            aop.judgeList = data.judgeList;
            console.log(data.judgeList);
            //类型分值
            aop.types.only = getTypeScore("单选题", data.paper.struc);
            aop.types.many.a = getTypeScore("多选题", data.paper.struc);
            aop.types.many.b = Math.floor(aop.types.many.a / 2);
            aop.types.judge = getTypeScore("判断题", data.paper.struc);
        }
    });
}
loadPaper();
function getTypeScore(tname, arr) {
    var types = arr.split(",");
    for (var i = 0; i < types.length; i++) {
        var sc = types[i].split("-");
        if (sc[0] == tname) {
            return sc[1];
        }
    }
    return "";
}
$("#only").change(
    function () {
        aop.types.only = parseInt($("#only").val());
    }
);
$("#many").change(
    function () {
        aop.types.many.a = parseInt($("#many").val());
    }
);
$("#judge").change(
    function () {
        aop.types.judge = parseInt($("#judge").val());
    }
);
$("#sss").change(
    function () {
        aop.paper.dura = parseInt($("#sss").val());
    }
);
$("#paper_name").change(
    function () {
        aop.paper.paper_name = $("#paper_name").val();
    }
);
$("#pass").change(
    function () {
        aop.paper.pass = parseInt($("#pass").val());
    }
);